﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

using RedPanda.MusicPlayer.DataModel;

namespace RedPanda.MusicPlayer.ViewModel
{
    /// <summary>
    /// 该类是绑定到PlaylistControl的ViewModel
    /// </summary>
    public class PlaylistViewModel
    {
        #region filed
        ObservableCollection<AudioFile> tracks;
        private int currentIndex;
        #endregion

        #region Constructor
        public PlaylistViewModel(Playlist list)
        {
            tracks = new ObservableCollection<AudioFile>();
            //将plylist中的加入到trakcs中;

            foreach (AudioFile af in list.Tracks)
            {
                tracks.Add(af);
            }

            currentIndex = tracks.Count>0?0:-1;
        }
        #endregion

        #region Property
        public int CurrentIndex
        {
            get
            {
                return currentIndex;
            }
            set{
                if(value>=0&&value<tracks.Count)
                    currentIndex=value;
            }
        }

        public AudioFile CurrentTrack
        {
            get
            {
                return tracks[currentIndex];
            }

        }

        public ObservableCollection<AudioFile> Tracks
        {
            get
            {
                return tracks;
            }
            set
            {
                tracks = value;
            }
        }
        #endregion

        /// <summary>
        /// 移动到下一首歌;
        /// </summary>
        public void MoveToNext()
        {
            if (currentIndex < tracks.Count)
                currentIndex++;
        }

        public void MoveToPrevious()
        {
            if (currentIndex > 0)
                currentIndex--;
        }

    }
}
